﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_member
	/// </summary>
	public partial class enterprise_member
	{
		public enterprise_member()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_mid", "enterprise_member"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_mid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_mid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_mid;

			int result= DbHelperSQL.RunProcedure("enterprise_member_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.enterprise_member model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_mid", SqlDbType.Int,4),
					new SqlParameter("@memberclass", SqlDbType.NChar,4),
					new SqlParameter("@membertime", SqlDbType.SmallInt,2),
					new SqlParameter("@ucount", SqlDbType.SmallInt,2),
					new SqlParameter("@releasejobcount", SqlDbType.SmallInt,2),
					new SqlParameter("@fristjobcount", SqlDbType.SmallInt,2),
					new SqlParameter("@fee", SqlDbType.Float,8)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.memberclass;
			parameters[2].Value = model.membertime;
			parameters[3].Value = model.ucount;
			parameters[4].Value = model.releasejobcount;
			parameters[5].Value = model.fristjobcount;
			parameters[6].Value = model.fee;

			DbHelperSQL.RunProcedure("enterprise_member_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_member model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_mid", SqlDbType.Int,4),
					new SqlParameter("@memberclass", SqlDbType.NChar,4),
					new SqlParameter("@membertime", SqlDbType.SmallInt,2),
					new SqlParameter("@ucount", SqlDbType.SmallInt,2),
					new SqlParameter("@releasejobcount", SqlDbType.SmallInt,2),
					new SqlParameter("@fristjobcount", SqlDbType.SmallInt,2),
					new SqlParameter("@fee", SqlDbType.Float,8)};
			parameters[0].Value = model.enterprise_mid;
			parameters[1].Value = model.memberclass;
			parameters[2].Value = model.membertime;
			parameters[3].Value = model.ucount;
			parameters[4].Value = model.releasejobcount;
			parameters[5].Value = model.fristjobcount;
			parameters[6].Value = model.fee;

			DbHelperSQL.RunProcedure("enterprise_member_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_mid)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_mid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_mid;

			DbHelperSQL.RunProcedure("enterprise_member_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_midlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from enterprise_member ");
			strSql.Append(" where enterprise_mid in ("+enterprise_midlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.enterprise_member GetModel(int enterprise_mid)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_mid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_mid;

			lcmyjobs.Model.enterprise_member model=new lcmyjobs.Model.enterprise_member();
			DataSet ds= DbHelperSQL.RunProcedure("enterprise_member_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["enterprise_mid"]!=null && ds.Tables[0].Rows[0]["enterprise_mid"].ToString()!="")
				{
					model.enterprise_mid=int.Parse(ds.Tables[0].Rows[0]["enterprise_mid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["memberclass"]!=null && ds.Tables[0].Rows[0]["memberclass"].ToString()!="")
				{
					model.memberclass=ds.Tables[0].Rows[0]["memberclass"].ToString();
				}
				if(ds.Tables[0].Rows[0]["membertime"]!=null && ds.Tables[0].Rows[0]["membertime"].ToString()!="")
				{
					model.membertime=int.Parse(ds.Tables[0].Rows[0]["membertime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ucount"]!=null && ds.Tables[0].Rows[0]["ucount"].ToString()!="")
				{
					model.ucount=int.Parse(ds.Tables[0].Rows[0]["ucount"].ToString());
				}
				if(ds.Tables[0].Rows[0]["releasejobcount"]!=null && ds.Tables[0].Rows[0]["releasejobcount"].ToString()!="")
				{
					model.releasejobcount=int.Parse(ds.Tables[0].Rows[0]["releasejobcount"].ToString());
				}
				if(ds.Tables[0].Rows[0]["fristjobcount"]!=null && ds.Tables[0].Rows[0]["fristjobcount"].ToString()!="")
				{
					model.fristjobcount=int.Parse(ds.Tables[0].Rows[0]["fristjobcount"].ToString());
				}
				if(ds.Tables[0].Rows[0]["fee"]!=null && ds.Tables[0].Rows[0]["fee"].ToString()!="")
				{
					model.fee=decimal.Parse(ds.Tables[0].Rows[0]["fee"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_mid,memberclass,membertime,ucount,releasejobcount,fristjobcount,fee ");
			strSql.Append(" FROM enterprise_member ");
            
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}

			return DbHelperSQL.Query(strSql.ToString());
		}

        /// <summary>
        /// 获得数据列表,表2是企业名字
        /// </summary>
        public DataSet GetList(int enterprise_bid)
        {
            SqlParameter[] para = {new SqlParameter("@enterprise_bid",SqlDbType.Int) };

            para[0].Value = enterprise_bid;

            return DbHelperSQL.RunProcedure("P_Get_enterprise_member", para, "ds");
        }

        /// <summary>
        /// 获得会员名称列表
        /// </summary>
        public DataSet GetMemberclassList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct memberclass ");
            strSql.Append(" FROM enterprise_member ");
           
            return DbHelperSQL.Query(strSql.ToString());
        }

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_mid,memberclass,membertime,ucount,releasejobcount,fristjobcount,fee ");
			strSql.Append(" FROM enterprise_member ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_member";
			parameters[1].Value = "enterprise_mid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

